import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.PropertiesCredentials;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.IOException;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.stub;

/**
 * User: Lee
 * Date: 8/13/13
 * Time: 10:27 PM
 */
public class CredentialTests {

    private PropertiesCredentials mockCreds = mock(PropertiesCredentials.class);

    @Before
    public void Setup() {
        stub(mockCreds.getAWSAccessKeyId()).toReturn("ABCDEFG1234567");
        stub(mockCreds.getAWSSecretKey()).toReturn("1234567ABCDEFG");
    }

    @Test
    public void CredentialsInstantiatedFromProperties() {

        // equivalent to a property file
        StringBuffer props = new StringBuffer("accessKey=ABCDEFG1234567\n");
        props.append("secretKey=1234567ABCDEFG");

        try {
            PropertiesCredentials creds = new PropertiesCredentials(new ByteArrayInputStream(props.toString().getBytes( "UTF-8" )));

            Assert.assertNotNull(creds);
            Assert.assertEquals("AWSAccessKeys don't match.",  mockCreds.getAWSAccessKeyId(), creds.getAWSAccessKeyId());
            Assert.assertEquals("AWSSecretKeys don't match.",  mockCreds.getAWSSecretKey(), creds.getAWSSecretKey());

        } catch (IOException e) {
            e.printStackTrace();
        }
    }



}
